﻿//-----------------------------------------------------------------------
// <copyright file="Projects.cs" company="Microsoft Corporation">
//     Copyright Microsoft Corporation. All Rights Reserved. This code released under the terms of the Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.) This is sample code only, do not use in production environments.
// </copyright>
//-----------------------------------------------------------------------
namespace VisualStudioOnlineOData
{
    using System;
    using System.Collections.Generic;
    using System.Threading.Tasks;

    /// <summary>
    ///
    /// </summary>
    public static class Projects
    {
        /// <summary>
        /// Gets the projects asynchronous.
        /// </summary>
        /// <param name="credentials">The credentials.</param>
        /// <param name="onSuccessfulResult">The on successful result.</param>
        /// <returns></returns>
        public static async Task<IEnumerable<Models.Project>> GetProjectsAsync(Credentials credentials, Action<string> onSuccessfulResult = null)
        {
            var httpGet = await Http.GetAsync(new Uri("https://tfsodata.visualstudio.com/DefaultCollection/Projects"), credentials);
            if (httpGet == null)
            {
                return null;
            }

            var result = XMLDeserialiser.DeserialiseFromString<Models.Projects>(httpGet).Entry;
            if (onSuccessfulResult != null)
            {
                onSuccessfulResult(httpGet);
            }

            return result;
        }
    }
}